package sc
package test

import scala.io.Source

object Test6 {
  def main(args: Array[String]): Unit = {
    //4、每个班级的平均年龄
    val source = Source.fromFile("scala/data/students.csv")
    val list = source.getLines().toList
    val studentMap = list.map(e => {
      val sp = e.split(",")
      (sp(2), sp(4))
    }).groupBy {
      case (_, clazz) => clazz
    }.map {
      case (clazz,list) =>
        (clazz,list.map{
          case (age,_) =>
            age.toDouble
        }.sum./(list.length))
    }
    println(studentMap)
  }

}
